<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 50px;
            background-color: green;
            animation: change 5s infinite alternate;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        const oBox = document.querySelector('.box');
        let flag = true; // true 长大， false 缩小
        let min = 100;
        let max = 200;
        let cur = min;

        let change = () => {
                oBox.style.width = cur + 'px';
                if (flag) {
                    cur++;
                    if (cur >= max) {
                        flag = false;
                    }
                } else {
                    cur--;
                    if (cur <= min) {
                        flag = true;
                    }
                }

                // 变量 长大还是缩小？ 
            } // 1秒=1000ms requestAnimationFrame
            // setInterval在js中不够准确 
            (function animloop() {
                change();
                requestAnimationFrame(animloop);
            })()
    </script>
</body>

</html>